//
//  AppDelegate.m
//  Btpin
//
//  Created by Vic on 2019/3/17.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "AppDelegate.h"
#import "SigninViewController.h"
#import "TUIKit.h"

#import <WXApi.h>
#import "WXAuth.h"
#import <Bugly/Bugly.h>

#define TXIMAccountType @"36862"

#import "PersonalFirstInfoViewController.h"
#import "JobDetailViewController.h"

@interface AppDelegate ()<WXApiDelegate, BMKLocationAuthDelegate, TencentSessionDelegate>
{
    TencentOAuth *tencentOAuth;
}
@end

@implementation AppDelegate

- (void)onCheckPermissionState:(BMKLocationAuthErrorCode)iError {
//    NSString *ddd;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = COLOR_OF_WHITE;
    
    [self registNotification];
    
    // 需要注意的是请在 SDK 任何类的初始化以及方法调用之前设置正确的 AK
    [[BMKLocationAuth sharedInstance] checkPermisionWithKey:BaiduMapKey authDelegate:self];
    
    // 要使用百度地图，请先启动BaiduMapManager
    BMKMapManager *mapManager = [[BMKMapManager alloc] init];
    // 如果要关注网络及授权验证事件，请设定generalDelegate参数
    BOOL ret = [mapManager start:BaiduMapKey  generalDelegate:nil];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
    
    if (!FirstUse) {
        UD_SetOForK(isTouristsToken, isToken);
    }
    
    [self baseSetting];
    [DataToolsControl sharedManager].appJustOpen = YES;
    [DataToolsControl sharedManager].validJob = NO;
    
    //在register之前打开log, 后续可以根据log排查问题
//    [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) {
//        NSLog(@"WeChatSDK: %@", log);
//    }];
    
//    [WXApi registerApp:WXID universalLink:@"www.baidu.com"];
    [WXApi registerApp:WXID universalLink:URL_UniversalLinks];
//    tencentOAuth = [[TencentOAuth alloc] initWithAppId:QQID andDelegate:self];
    tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"1108893960" andDelegate:self];
    
    //调用自检函数
//    [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
//        NSLog(@"调用自检函数:%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
//    }];
    
    //此处替换为你的AppId
    [Bugly startWithAppId:@"976630ce6b"];
    
    
    [self customizeInterface];
    [AppDelegate loadLocationData];
    [self monitorNetwork];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushSignin) name:NotificationForTokenPastDue object:nil];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    
//    [self showViewController:TabBarTypeOfSignin];
//    self.window.rootViewController = [[PersonalTabBarController alloc] init];
//    self.window.rootViewController = [[CompanyTabBarController alloc] init];
    
    if (Signin) {
        if ([UD_GetOForK(isUserRole) isEqualToString:@"1"]) { // 1-招聘者
            [self showViewController:TabBarTypeOfCompany];
        } else {
            [self showViewController:TabBarTypeOfPersonal];
        }
        [DataToolsControl autoLogin];
    } else {
        [self showViewController:TabBarTypeOfSignin];
    }
    
    [self.window makeKeyAndVisible];
    
    return YES;
}
- (void)pushSignin {
    SVPHUDError(@"登录过期，请重新登录");
    [DataToolsControl deallocUserData];
    [self showViewController:TabBarTypeOfSignin];
}
- (void)registNotification {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }
}
/**
 *  在 AppDelegate 的回调中会返回 deviceToken，需要在登录后上报给腾讯云后台
**/
 - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
     // 记录下 Apple 返回的 deviceToken
     
     UD_SetOForK(deviceToken, isDeviceToken);
     UDSynchronize;
     return;
     
     if (iOS13) {
         if (![deviceToken isKindOfClass:[NSData class]]) return;
         const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
         NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x", ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]), ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
         NSLog(@"deviceToken:%@", hexToken);
         NSData *tokenData = [hexToken dataUsingEncoding:NSUTF8StringEncoding];
         UD_SetOForK(tokenData, isDeviceToken);
     } else {
         NSString *token = [NSString stringWithFormat:@"%@", deviceToken];
         token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];
         token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
         token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
         NSLog(@"deviceToken2 is: %@", token);
         NSData *tokenData = [token dataUsingEncoding:NSUTF8StringEncoding];
         UD_SetOForK(tokenData, isDeviceToken);
     }
     UDSynchronize;
//     [DataToolsControl sharedManager].deviceToken = deviceToken;
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error {
    NSLog(@"%@", error);
}


- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
    if ([DataToolsControl sharedManager].isTIMLoginSuccess) {
        __block UIBackgroundTaskIdentifier bgTaskID;
        bgTaskID = [application beginBackgroundTaskWithExpirationHandler:^ {
            //不管有没有完成，结束 background_task 任务
            [application endBackgroundTask: bgTaskID];
            bgTaskID = UIBackgroundTaskInvalid;
        }];
        /*
         //获取未读计数
         int unReadCount = 0;
         NSArray *convs = [[TIMManager sharedInstance] getConversationList];
         for (TIMConversation *conv in convs) {
         if ([conv getType] == TIM_SYSTEM) {
         continue;
         }
         unReadCount += [conv getUnReadMessageNum];
         }
         [UIApplication sharedApplication].applicationIconBadgeNumber = unReadCount;
         */
        
        //doBackground
        TIMBackgroundParam *param = [[TIMBackgroundParam alloc] init];
        //    [param setC2cUnread:unReadCount];
        [param setC2cUnread:0];
        [[TIMManager sharedInstance] doBackground:param succ:^() {
            NSLog(@"doBackgroud Succ");
        } fail:^(int code, NSString * err) {
            NSLog(@"Fail: %d->%@", code, err);
        }];
    }
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
    if (Signin) {
        if ([[TIMManager sharedInstance] getLoginStatus] != TIM_STATUS_LOGINED) {
            NSString *identifierStr = UD_GetOForK(isUserID);
            NSString *userSigStr = UD_GetOForK(isIMUserSig);
            NSString *appidAt3rdStr = UD_GetOForK(isIMAppID);
            if ((identifierStr && identifierStr.length) && (userSigStr && userSigStr.length) && (appidAt3rdStr && appidAt3rdStr.length)) {
                TIMLoginParam *login_param = [[TIMLoginParam alloc ]init];
                // identifier 为用户名，userSig 为用户登录凭证
                // appidAt3rd 在私有帐号情况下，填写与 sdkAppId 一样
                login_param.identifier = UD_GetOForK(isUserID);
                login_param.userSig = UD_GetOForK(isIMUserSig);
                login_param.appidAt3rd = UD_GetOForK(isIMAppID);
                [[TIMManager sharedInstance] login: login_param succ:^(){
                    [DataToolsControl sharedManager].isTIMLoginSuccess = YES;
                    NSLog(@"Init Succ");
                    NSData *tokenData = UD_GetOForK(isDeviceToken);
                    if (tokenData && tokenData.length) {
                        TIMTokenParam *param = [[TIMTokenParam alloc] init];
#if DEBUG
                        param.busiId = TIMPushDevID;
#else
                        param.busiId = TIMPushReleaseID;
#endif
                        [param setToken:UD_GetOForK(isDeviceToken)];
                        [[TIMManager sharedInstance] setToken:param succ:^{
                            NSLog(@"-----> 上传 token 成功 ");
                        } fail:^(int code, NSString *msg) {
                            NSLog(@"-----> 上传 token 失败 ");
                        }];
                    }
                } fail:^(int code, NSString * err) {
                    [DataToolsControl sharedManager].isTIMLoginSuccess = NO;
                    NSLog(@"Login Failed: %d->%@", code, err);
                }];
            }
        }
    }
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
    if ([DataToolsControl sharedManager].isTIMLoginSuccess) {
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
        [[NSNotificationCenter defaultCenter] postNotificationName:NotificationFor_Msg_UnReadCount object:nil];
        [[TIMManager sharedInstance] doForeground:^() {
            NSLog(@"doForegroud Succ");
        } fail:^(int code, NSString * err) {
            NSLog(@"Fail: %d->%@", code, err);
        }];
    }
}
- (void)applicationWillTerminate:(UIApplication *)application {
    if ([DataToolsControl sharedManager].isTIMLoginSuccess) {
        [[TIMManager sharedInstance] logout:^() {
            NSLog(@"logout succ");
        } fail:^(int code, NSString * err) {
            NSLog(@"logout fail: code=%d err=%@", code, err);
        }];
    }
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if ([url.scheme isEqualToString:WXID]) {
        return [WXApi handleOpenURL:url delegate:self];
//        return [WXAUTH handleOpenURL:url];
    } else if ([url.scheme isEqualToString:QQID]) {
        return [TencentOAuth HandleOpenURL:url];
    }
    return YES;
}
- (void)onReq:(BaseReq *)req {
    
}
- (void)onResp:(BaseResp *)resp {
    if ([resp isKindOfClass:[SendAuthResp class]]) {//判断是否为授权登录类
        SendAuthResp *req = (SendAuthResp *)resp;
        if([req.state isEqualToString:@"wx_oauth_authorization_state"]){//微信授权成功
            if (req.errCode == 0) {
                NSLog(@"获取code：%@", req.code);
                
                UD_SetOForK(req.code, isOpenWXSigninCode);
                UDSynchronize;
                
                [DataToolsControl sharedManager].codeRecord = 1;
                [DataToolsControl sharedManager].isApple = NO;
                [DataToolsControl sharedManager].isWXSigninCode = req.code;
                [[NSNotificationCenter defaultCenter] postNotificationName:NotificationForWXCode object:nil userInfo:@{@"code":req.code}];
            }
        }
    }
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
    return [WXApi handleOpenUniversalLink:userActivity delegate:self];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(nonnull NSURL *)url {
//    NSString *handle =  [[NSUserDefaults standardUserDefaults] objectForKey:@"handleOpenURL"];
    
    if ([url.scheme isEqualToString:WXID]) {
        return [WXApi handleOpenURL:url delegate:self];
//        return [WXApi handleOpenURL:url delegate:[DataToolsControl sharedManager]];
//        return [WXAUTH handleOpenURL:url];
    } else if ([url.scheme isEqualToString:QQID]) {
        return [TencentOAuth HandleOpenURL:url];
    }
    return  YES;
//    return  [WXApi handleOpenURL:url delegate:self];
}
- (BOOL)application:(UIApplication *)app openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
//    NSString *handle =  [[NSUserDefaults standardUserDefaults] objectForKey:@"handleOpenURL"];
    
    if ([url.scheme isEqualToString:WXID]) {
        return [WXApi handleOpenURL:url delegate:self];
//        return [WXApi handleOpenURL:url delegate:[DataToolsControl sharedManager]];
//        return [WXAUTH handleOpenURL:url];
    } else if ([url.scheme isEqualToString:OpenBtpin]) {
        if (Signin) {
            if ([UD_GetOForK(isUserRole) isEqualToString:@"2"]) {
                NSDictionary *dic = [UIToolsControl getParamsWithUrlString:url.absoluteString];
                NSString *page = [UIToolsControl URLDecodedString:dic[@"page"]];
                if ([page isEqualToString:@"job_detail"]) { // 职位详情
                    NSString *job_id = [UIToolsControl URLDecodedString:dic[@"job_id"]];
                    if (job_id && job_id.length) {
                        JobDetailViewController *JDVC = [[JobDetailViewController alloc] init];
                        JDVC.id = job_id;
                        JDVC.showSettingFlag = NO;
                        JDVC.hidesBottomBarWhenPushed = YES;
                        
                        PersonalTabBarController *tabBarController = (PersonalTabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                        tabBarController.selectedIndex = 0;
                        RootNavigationController *showNav = (RootNavigationController *)tabBarController.selectedViewController;
                        [showNav pushViewController:JDVC animated:YES];
                    }
                }
            }
        } else {
            [self showViewController:TabBarTypeOfSignin];
        }
    }
    
    return YES;
}
/*
// 从微信分享过后点击返回应用的时候调用
- (void)onResp:(BaseResp *)resp {
    if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
        //把返回的类型转换成与发送时相对于的返回类型,这里为SendMessageToWXResp
//        SendMessageToWXResp *sendResp = (SendMessageToWXResp *)resp;
        
        //使用UIAlertView 显示回调信息
//        NSString *str = [NSString stringWithFormat:@"%d",sendResp.errCode];
//        UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"回调信息" message:str delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
//        [alertview show];
    }
    
    if([resp isKindOfClass:[PayResp class]]){
        //zf返回结果,zf支付结果需要去微信服务器端查询
        
    }
    
    if ([resp isKindOfClass:[SendAuthResp class]]){//判断是否为授权登录类
        SendAuthResp *req = (SendAuthResp *)resp;
        if([req.state isEqualToString:@"wx_oauth_authorization_state"]){//微信授权成功
            req.code; //获得code
        }
    }
}
*/


#pragma mark - 切换根视图
- (void)showViewController:(TabBarType)type {
    if (self.signinVC) {
        [self.signinVC removeFromParentViewController];
        self.signinVC = nil;
    }
    if (self.companyTabBarC) {
        [self.companyTabBarC removeFromParentViewController];
        self.companyTabBarC = nil;
    }
    if (self.personalTabBarC) {
        [self.personalTabBarC removeFromParentViewController];
        self.personalTabBarC = nil;
    }
    switch (type) {
        case TabBarTypeOfCompany: {
            self.companyTabBarC = [[CompanyTabBarController alloc] init];
            self.window.rootViewController = self.companyTabBarC;
        } break;
        case TabBarTypeOfPersonal: {
            self.personalTabBarC = [[PersonalTabBarController alloc] init];
            self.window.rootViewController = self.personalTabBarC;
        } break;
        case TabBarTypeOfSignin: {
//            if (self.signinVC) {
//                self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.signinVC];
//            } else {
//                self.signinVC = [[SigninViewController alloc] init];
//                self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.signinVC];
//            }
            self.signinVC = [[SigninViewController alloc] init];
            self.window.rootViewController = [[RootNavigationController alloc] initWithRootViewController:self.signinVC];
        } break;
        default:
            break;
    }
}

- (void)monitorNetwork { // 监听网络状况
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch(status) {
            case AFNetworkReachabilityStatusNotReachable: { // 当前设备无网络
                if (Signin) {
                    TIMLoginParam * login_param = [[TIMLoginParam alloc ] init];
                    // identifier 为用户名
                    // appidAt3rd 在私有帐号情况下，填写与 sdkAppId 一样
                    login_param.identifier = UD_GetOForK(isUserID);
                    login_param.appidAt3rd = UD_GetOForK(isIMAppID);
//                    [[TIMManager sharedInstance] initStorage: login_param succ:^(){
                    [[TIMManager sharedInstance] initStorage: UD_GetOForK(isUserID) succ:^(){
                        [DataToolsControl sharedManager].isTIMLoginSuccess = YES;
                        NSLog(@"Init Succ");
//                        if ([DataToolsControl sharedManager].deviceToken && [DataToolsControl sharedManager].deviceToken.length) {
                        NSData *tokenData = UD_GetOForK(isDeviceToken);
                        if (tokenData && tokenData.length) {
                            TIMTokenParam *param = [[TIMTokenParam alloc] init];
#if DEBUG
                            param.busiId = TIMPushDevID;
#else
                            param.busiId = TIMPushReleaseID;
#endif
//                            [param setToken:[DataToolsControl sharedManager].deviceToken];
                            [param setToken:UD_GetOForK(isDeviceToken)];
                            [[TIMManager sharedInstance] setToken:param succ:^{
                                NSLog(@"-----> 上传 token 成功 ");
                            } fail:^(int code, NSString *msg) {
                                NSLog(@"-----> 上传 token 失败 ");
                            }];
                        }
                    } fail:^(int code, NSString * err) {
                        [DataToolsControl sharedManager].isTIMLoginSuccess = NO;
                        NSLog(@"Init Failed: %d->%@", code, err);
                    }];
                }
            } break;
            case AFNetworkReachabilityStatusUnknown:
            case AFNetworkReachabilityStatusReachableViaWWAN: // 当前蜂窝移动网络
            case AFNetworkReachabilityStatusReachableViaWiFi:{ // 当前Wi-Fi网络
                [AppDelegate loadLocationData];
            } break;
            default:
                break;
                
        }}];
    [mgr startMonitoring];
}
+ (void)loadLocationData {
    [DataToolsControl sharedManager].allCategoryInfoModel = [[PublicAllCategoryInfoModel alloc] init];
    [DataToolsControl getPublicAllCategory];
    [DataToolsControl getPublicCountryCode];
    [DataToolsControl getPublicJobCats];
    
    return;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:AllCategoryDataFilePath]) {
        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:AllCategoryDataFilePath];
        
        [DataToolsControl sharedManager].allCategoryInfoModel = [[PublicAllCategoryInfoModel alloc] init];
        [[DataToolsControl sharedManager].allCategoryInfoModel setValuesForKeysWithDictionary:dic];
        
        NSDictionary *dic1 = [NSDictionary dictionaryWithContentsOfFile:AllCategoryForJobCatsDataFilePath];
        [DataToolsControl handleJobCatsData:dic1];
        
        NSDictionary *dic2 = [NSDictionary dictionaryWithContentsOfFile:AllCategoryForCountryCodeDataFilePath];
        [DataToolsControl handleCountryCodesData:dic2];
        
        
        /*
         if ([fileManager removeItemAtPath:AllCategoryDataFilePath error:nil]) {
         NSLog(@"dele success");
         } else {
         NSLog(@"dele fail");
         }
         */
    } else {
        [DataToolsControl sharedManager].allCategoryInfoModel = [[PublicAllCategoryInfoModel alloc] init];
        [DataToolsControl getPublicAllCategory];
        [DataToolsControl getPublicCountryCode];
        [DataToolsControl getPublicJobCats];
    }
}



- (void)customizeInterface {
    if (@available(iOS 11.0, *)) {
        [UITableView appearance].estimatedRowHeight = 0;
        [UITableView appearance].estimatedSectionHeaderHeight = 0;
        [UITableView appearance].estimatedSectionFooterHeight = 0;
    }
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD setMinimumDismissTimeInterval:SVPHUDDismissTime];
    
    //系统返回按钮处的title偏移到可视范围之外
    UIOffset offset = (iOS11||iOS12) ? UIOffsetMake(-200, 0) : UIOffsetMake(0, -80);
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsCompact];
    
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
//    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
//    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
//    [[UINavigationBar appearance] setShadowImage:[UIToolsControl getCustomImageWithRect:CGRectMake(0, 0, WIDTH, 0.5) color:THEMECOLOR_OF_TEXT_cccccc]];
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:Font(Font_18), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_333333}];
//    [[UINavigationBar appearance] setBarTintColor:COLOR_OF_WHITE];
//    [[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"nav_bottom_line"]];
    
    
    [[UITabBar appearance] setTranslucent:NO];
    
//    [[UITabBar appearance] setBarTintColor:COLOR_OF_WHITE];
    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:THEMECOLOR_OF_ORANGE} forState:UIControlStateSelected];
    if (@available(iOS 10.0, *)) {
        [[UITabBarItem appearance] setBadgeColor:THEMECOLOR_OF_RED];
    }
    
    [[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];
//    [[UITableView appearance] setSeparatorInset:UIEdgeInsetsMake(0, 10*Scale, 0, 10*Scale)];
    [[UITableView appearance] setSeparatorColor:THEMECOLOR_OF_TEXT_cccccc];
}
/**
 *  键盘设置
 */
- (void)baseSetting {
    [UITextField appearance].tintColor = THEMECOLOR_OF_ORANGE;
    [UITextView appearance].tintColor = THEMECOLOR_OF_ORANGE;
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;
    manager.shouldToolbarUsesTextFieldTintColor = YES;
    manager.enableAutoToolbar = YES;
}
- (void)tencentDidLogin {
    
}
- (void)tencentDidNotLogin:(BOOL)cancelled {
    
}
- (void)tencentDidNotNetWork {
    
}



/// 在这里写支持的旋转方向，为了防止横屏方向，应用启动时候界面变为横屏模式
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    // 可以这么写
    if (self.allowOrentitaionRotation) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    return UIInterfaceOrientationMaskPortrait;
}



@end
